package cn.ava.ymcc.web.controller;

import cn.ava.ymcc.doc.CourseDoc;
import cn.ava.ymcc.dto.CourseEsSearchDto;
import cn.ava.ymcc.result.JSONResult;
import cn.ava.ymcc.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class CourseEsController {

    @Autowired
    private ICourseEsService courseEsService;

    @PostMapping("/save")
    @PreAuthorize("hasAuthority('es:saveCourse')")
    public JSONResult saveCourse(@RequestBody CourseDoc doc){
        courseEsService.saveCourse(doc);
        return JSONResult.success();
    }

    @DeleteMapping("/delete")
    public JSONResult deleteCourse(@RequestBody CourseDoc doc){
        courseEsService.deleteCourse(doc);
        return JSONResult.success();
    }

    @PostMapping("/search")
    public JSONResult search(@RequestBody CourseEsSearchDto doc){
        return JSONResult.success(courseEsService.search(doc));
    }
    


}
